/**
 * 规则配置相关类型定义
 */

// 规则基本信息
export interface RuleBasicInfo {
  id?: string;
  name: string;
  description?: string;
  status: 'active' | 'disabled';
  creator?: string;
  createTime?: string;
  updateTime?: string;
}

// 数据表信息
export interface DataTable {
  tableName: string;
  tableComment: string;
  fields: TableField[];
}

// 表字段信息
export interface TableField {
  fieldName: string;
  fieldType: string;
  fieldComment: string;
  isPrimaryKey: boolean;
  isForeignKey: boolean;
}

// 表关联关系
export interface TableJoin {
  leftTable: string;
  leftField: string;
  rightTable: string;
  rightField: string;
  joinType: 'INNER' | 'LEFT' | 'RIGHT';
}

// 筛选条件
export interface FilterCondition {
  id: string;
  tableName: string;
  fieldName: string;
  operator: FilterOperator;
  value: any;
  logic?: 'AND' | 'OR';
}

// 筛选操作符
export type FilterOperator = 
  | '=' 
  | '!=' 
  | '>' 
  | '>='
  | '<'
  | '<='
  | 'LIKE'
  | 'NOT LIKE'
  | 'IN'
  | 'NOT IN'
  | 'BETWEEN';

// 分组字段
export interface GroupByField {
  tableName: string;
  fieldName: string;
  alias?: string;
}

// 聚合函数
export interface AggregateFunction {
  function: AggregateType;
  tableName: string;
  fieldName: string;
  alias: string;
}

// 聚合函数类型
export type AggregateType = 'COUNT' | 'SUM' | 'AVG' | 'MAX' | 'MIN' | 'COUNT_DISTINCT';

// 规则配置完整信息
export interface RuleConfig {
  basicInfo: RuleBasicInfo;
  tables: string[];
  joins: TableJoin[];
  conditions: FilterCondition[];
  groupBy: GroupByField[];
  aggregates: AggregateFunction[];
}

// 规则预览结果
export interface RulePreview {
  estimatedRows: number;
  estimatedTime: number;
  sampleData: Record<string, any>[];
  sqlPreview: string;
}

// 规则列表查询参数
export interface RuleListParams {
  page: number;
  size: number;
  name?: string;
  status?: string;
  creator?: string;
  startTime?: string;
  endTime?: string;
}

// 规则列表响应
export interface RuleListResponse {
  list: RuleBasicInfo[];
  total: number;
  page: number;
  size: number;
}

// API响应统一格式
export interface ApiResponse<T> {
  code: number;
  message: string;
  data: T;
  success: boolean;
  timestamp?: string;
}